#!/bin/sh
#
#
# COPYRIGHT 2004, EMULEX CORPORATION
# 3333 Susan Street, Costa Mesa, CA 92626
# 
# All rights reserved.  This computer program and related documentation
# is protected by copyright and distributed under licenses restricting
# its use, copying, distribution and decompilation.  This computer
# program and its documentation are CONFIDENTIAL and a TRADE SECRET
# of EMULEX CORPORATION.  The receipt or possession of this program
# or its documentation does not convey rights to reproduce or disclose
# its contents, or to manufacture, use, or sell anything that it may
# describe, in whole or in part, without the specific written consent
# of EMULEX CORPORATION.  Any reproduction of this program without
# the express written consent of EMULEX CORPORATION is a violation
# of the copyright laws and may subject you to criminal prosecution.
#
#
# RedHat config info
#
# chkconfig: 2345 99 10
# description: ElxDiscSrv - Discovery Service for HBAnyware/AutoPilot
#
# Suse config info
#
#
### BEGIN INIT INFO
# Provides:       ElxDiscSrv
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    Loads or unloads Emulex Discovery Service for HBAnyware/AutoPilot
### END INIT INFO
#
#
case "$1" in
'start')
	if [ -f /etc/emulexDiscConfig ]; then
		/bin/grep "AUTOSTART:true" /etc/emulexDiscConfig >/dev/null 2>&1
		if [ $? -eq 0 ]; then
			if [ -f /usr/sbin/hbanyware/start_elxdiscovery ]; then
				echo 'starting Emulex Discovery Daemon'
				/usr/sbin/hbanyware/start_elxdiscovery &
			fi
		fi
	fi
	;;
 
'stop')
#               Kill parent elxdiscoveryd
		ppid=`ps -eaf | grep elxdisc | grep -v grep | awk '{ print $2 }' | sort -n | head -1`
		if [ ! -z "$ppid" ];then
			kill $ppid > /dev/null 2>&1
		fi

#               Kill any zombied elxdiscoveryd children
		for ppid in `ps -eaf | grep elxdisc | grep -v grep | awk '{ print $2 }' | sort -n`
		do
			kill -9 $ppid > /dev/null 2>&1
		done
	;;

*)
        echo "Usage: $0 { start | stop }"
        exit 1
        ;;
esac
exit 0
